package itheima.JavaSE.Test;

public class Product {
//    包含商品名称、价格、库存数量等属性，和基本get/set方法。（1分）
    private String name;
    private double price;
    private int quantity;

//    定义获取商品信息方法，返回商品名称、价格、库存数量
    public String getProductInfo(){
        return name+"\t"+price+"\t"+quantity;
    }
//     定义增加库存和减少库存的方法。（3分）
    //增加库存
    public void addProduct(int quantity){
        this.quantity += quantity;
    }
    //减少库存
    public void reduceProduct(int quantity){
//        检查当前商品对象的库存数量是否小于要减少的数量
        if (this.quantity<quantity){
            System.out.println("商品库存不足");
        }else {
            this.quantity -= quantity;
        }
    }

    public String toString() {
        return "商品信息{" +
                "名称='" + name + '\'' +
                ", 价格=" + price +
                ", 数量=" + quantity +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Product() {
    }

    public Product(String name, double price, int quantity) {
        this.name = name;
        this.price = price;
        this.quantity = quantity;
    }
}
